﻿using System.Windows;
using System.Windows.Media;

namespace uTrade.Controls
{
    public class DrawingRegion : FrameworkElement
    {
        public double LeftFixWidth = 50; //左侧固定宽度
        public double RightFixWidth = 50;//右侧固定宽度
        public double TopFixWidth { set; get; }  //顶部固定高度
        public double BottomFixWidth { set; get; }//底部固定高度

        public Thickness ChartMargin;  //边界

        private double _totalWidth;
        private double _totalHeight;

        public double TotalWidth
        {
            get
            {
                return _totalWidth;
            }
        }

        public double TotalHeight
        {
            get
            {
                return _totalHeight;
            }
        }

        public double ChartStartX
        {
            get
            {
                return LeftFixWidth;
            }
        }

        public double ChartStartY
        {
            get
            {
                return TopFixWidth;
            }
        }

        public double ChartEndX
        {
            get
            {
                return TotalWidth - RightFixWidth;
            }
        }

        public double ChartEndY
        {
            get
            {
                return TotalHeight - BottomFixWidth;
            }
        }

        public double ChartWidth
        {
            get
            {
                return ChartEndX - ChartStartX;
            }
        }

        public double ChartHeight
        {
            get
            {
                return ChartEndY - ChartStartY;
            }
        }

        public DrawingRegion()
        {
        }

        protected override void OnRender(DrawingContext dc)
        {
            base.OnRender(dc);
            this._totalWidth = this.ActualWidth;
            this._totalHeight = this.ActualHeight;
        }

        //判断坐标是否在矩形框内
        public bool InChart(Point point)
        {
            //Point point = Mouse.GetPosition(this);
            //uLog.LogError(string.Format("x:{0},y:{1}", point.X, point.Y));

            if ((point.X >= ChartStartX && point.X <= ChartEndX)
                && (point.Y >= ChartStartY && point.Y <= ChartEndY))
            {
                return true;
            }
            return false;
        }
    }
}